package rsschart.feed;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import rsschart.charter.BarChart;

public class RssChart {
	private String title;
	private String link;
	private int width;
	private int height;
	private DataSets dataSets;
	private Category category;
		
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public DataSets getDataSets() {
		return dataSets;
	}

	public void setDataSets(DataSets dataSets) {
		this.dataSets = dataSets;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}
	
	public void addDataSet(DataSet dataSet) {
		if (this.dataSets==null) {
			this.dataSets = new DataSets();
		}
		this.dataSets.add(dataSet);
	}

	public void setDataSetsName(String dataSetsName) {
		if (this.dataSets==null) {
			this.dataSets = new DataSets();
		}
		this.dataSets.setName(dataSetsName);
	}
	
	public String getDataSetsName() {
		if (!(this.dataSets==null)) {
			return this.dataSets.getName();
		}
		else {
			return null;
		}
	}

	public void setDataSetsValueLabel(String dataSetsValueLabel) {
		if (this.dataSets==null) {
			this.dataSets = new DataSets();
		}
		this.dataSets.setValueLabel(dataSetsValueLabel);
	}
	
	public String getDataSetsValueLabel() {
		if (!(this.dataSets==null)) {
			return this.dataSets.getValueLabel();
		}
		else {
			return null;
		}
	}
	
	public DataSet getDataSet(int i) {
		return dataSets.getDataSet(i);
	}

	
	
	public static String[] parseValues(String valueString) {
		int tokes;
		int idx=0;
		StringTokenizer toke = new StringTokenizer(valueString, ":", false);
		tokes = toke.countTokens();
		String[] vals = new String[tokes];
		while(toke.hasMoreTokens()) {
			vals[idx]=toke.nextToken();
			idx++;
		}
		return vals;
	}
	
	public int getSeriesPointCount() {
		String[] vals = parseValues(category.getValueString());
		
		return vals.length;
	}
	
	public int getDataSetCount(){
		return dataSets.size();
	}
	
	
	public static void main(String args[]) {
		
		RssChart rss = new RssChart();
		String[] vals;
		Category catg = new Category();
		DataSet dataSet = new DataSet();
				
		vals = parseValues("1:3:5:7:9:23");
		
		int l = vals.length;
		for(int i=0;i<l;i++) {
			System.out.println(vals[i]);
		}
		
		rss.setTitle("Pets that Jen Wants");
		rss.setWidth(800);
		rss.setHeight(600);
		
		//catg.setId("pets");
		catg.setName("pets");
		catg.setValueString("Llama:Dogs:Cats:Ducks:Birds:Fish");
		
		//dataSet.setId("count");
		dataSet.setName("Pet Count");
		dataSet.setValueString("1:8:5:2:3:11");

		DataSets dataSets = new DataSets();
		dataSets.add(dataSet);
		rss.setDataSets(dataSets);
		rss.setCategory(catg);
		
		BarChart barChart = new BarChart();
		
		String content;
		content = barChart.draw(rss);
		
		System.out.println(content);
	}
}